#!/bin/bash

PATH=/usr/bin:/usr/local/bin:/usr/local/mysql/bin:$PATH

usage()
{
	echo ""
	echo "  usage: $0 -u usuario -p password -h host"
	echo
}




USUARIO=""
PASSWORD=""
HOST=""

while getopts ":u:p:h:" opt; do
        case $opt in
        u)
                USUARIO=$OPTARG
        ;;
        p)
                PASSWORD=$OPTARG
        ;;
        h)
                HOST=$OPTARG
        ;;
        \?)
                echo "Invalid option: -$OPTARG" >&2
                usage
                exit 1
        ;;
        :)
                echo "Option -$OPTARG requires an argument." >&2
                usage
                exit 1
        ;;
        esac
done

if [ "$USUARIO" == "" ] || [ "$PASSWORD" == "" ] || [ "$HOST" == "" ]
then
        usage
        exit 1
fi


for db in `mysql -u $USUARIO --password=$PASSWORD -h $HOST -BN -e "show databases;"`
do
        for tabla in `mysql -u $USUARIO --password=$PASSWORD -h $HOST -BN -e "show tables;"`
        do
                mysql -u $USUARIO --password=$PASSWORD -h $HOST -BN -e "check table $tabla;" $db
        done
done


